import { takeEvery, put } from "redux-saga/effects"
import { GET_SAGA_TASK_LIST } from "./actionTypes"
import { getTaskListAction } from "./actionCreators";
import axios from 'axios'

// generator 函数
function* mySagas() {
  // 等待捕获 action
  yield takeEvery(GET_SAGA_TASK_LIST, getSagaTaskList)
}

function* getSagaTaskList() {
  const response = yield axios.get('https://www.fastmock.site/mock/21a510471fabc5e57f4ef5267cb2dbf5/reactRedux/taskList')
  const action = getTaskListAction(response.data)
  yield put(action)
}

export default mySagas